package huoye.shops.huoye.operation.widget;

import android.content.Context;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.SimpleAdapter;
import android.widget.TextView;

import com.codeideology.android.widget.ios.dialog.base.BaseDialog;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import huoye.shops.R;




/**
 * Created by uesr on 2018/8/11.
 */

public class DiscountSelectDialog extends BaseDialog<DiscountSelectDialog> {



    private Context mContext;

    //定义以及初始化数据
    private List<Map<String,Object>> dataList;
    private ImageView ivOut;
    private GridView gridView;

    public DiscountSelectDialog(Context context) {
        super(context);
        this.mContext = context;
    }


    @Override
    public View onCreateView() {
        widthScale(0.85f);
        View inflate = View.inflate(context, R.layout.dialog_discount_select, null);
        ivOut = (ImageView) inflate.findViewById(R.id.dialog_discound_select_iv_out);
        dataList = new ArrayList<>();
        gridView = (GridView) inflate.findViewById(R.id.dialog_discound_select_gv);
        SimpleAdapter simpleAdapter = new SimpleAdapter(mContext, getData(), R.layout.item_discount_select, new String[]{"txt"}, new int[]{R.id.item_discount_select_bv});
        gridView.setAdapter(simpleAdapter);

       /* gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                listener.onDiscountSelectClick(i);
                dismiss();

            }
        });*/


        return inflate;
    }

    private List<Map<String, Object>> getData() {
        for (int i=0; i< 9; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            map.put("txt", (i+1)+"折");
            dataList.add(map);
        }
        return dataList;
    }

    @Override
    public void setUiBeforShow() {
        ivOut.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dismiss();
            }
        });

        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                listener.onDiscountSelectClick(i);
                dismiss();

            }
        });
}




    public interface OnDiscountSelectListener {
        void onDiscountSelectClick(int i);

    }
    public void setOnDiscountSelectListener(OnDiscountSelectListener onListener) {
        this.listener = onListener;
    }

    private OnDiscountSelectListener listener;

}
